Imports System.Data.SqlClient

Partial Class companyList
    Inherits System.Web.UI.Page
    Dim objrd As SqlDataReader = Nothing
    Private i As Integer
    Private pages As Integer

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim objdt = New GetData
        Dim strErr As String
        Dim ps As New PreparedStatement("")
        strErr = ""
        Dim sum, sumdesc As Integer
        i = Request("page")
        If i = Nothing Or i = 0 Then
            i = 1
        End If
        ps.strSql = "select count(*) from merchant_info where lang_flag='en'"
        Dim conn As SqlConnection = objdt.getConn()

        objrd = objdt.dr(ps, strErr, conn, objrd)
        objrd.Read()
        sum = objrd.Item(0)
        pages = (sum \ 10) + 1
        If i >= pages Then
            i = pages
        ElseIf i <= 0 Then
            i = 1
        End If
        If (i = pages) Then
            sumdesc = sum
        Else
            sumdesc = i * 10
        End If
        totalPage.InnerText = i.ToString & "/" & pages.ToString()
        totalPage1.InnerText = i.ToString & "/" & pages.ToString()
        resultNum.InnerText = sum.ToString & "Results"

        ps.strSql = "select top(" & i & "*10) * from merchant_info where lang_flag='en' " & _
                    "and id not in (" & _
                    "select top (" & i - 1 & "*10) id from merchant_info where lang_flag='en' " & _
                    "order by company_name" & _
                    ") and id not in (select top(" & sum - sumdesc & ") id from merchant_info where lang_flag='en' " & _
                    "order by company_name desc) order by company_name"

        ' ps.strSql = "select * from merchant_info where lang_flag='en' order by company_name "
        objrd = objdt.dr(ps, strErr, conn, objrd)
        Dim strCom, country, countryCode As String
        strCom = ""
        If objrd.HasRows Then

            While (objrd.Read())
                If (objrd.Item("country").ToString.ToLower.Equals("china")) Then
                    country = "../assets/cn.gif"
                    countryCode = "china"
                ElseIf (objrd.Item("country").ToString.ToLower.Equals("usa")) Then
                    country = "../assets/us.gif"
                    countryCode = "usa"
                End If
                strCom &= "<div class=""itemBox"">" & _
                              "<div class=""companyLocationStyle loaction"">" & _
                                  "<img style=""border: 0pt none; vertical-align: top;"" alt=""country flag"" src=""" & country & """/>" & _
                                  "<span style=""display:block"">  " & objrd.Item("country") & "</span>" & _
                              "</div>" & _
                              "<div class=""companyShortInfo"">" & _
                                  "<div class=""companyName"">" & _
                                      "<a target=""_blank"" title=""Georgia Company"" dot=""area=ml2&type;=pttl&value;="" href=""company.aspx?cId=" & objrd.Item("company_id") & """ > " & _
                                            objrd.Item("company_name") & _
                                      "</a>" & _
                                  "</div>" & _
                                  "<div class=""companyDescription"">" & _
                                     "Products/Services : " & objrd.Item("brief") & _
                                 "</div>" & _
                              "</div>" & _
                          "</div>"
            End While

        End If
        objdt.closeConn(conn)

        prePage.HRef = "companylist.aspx?page=" & i - 1
        nextPage.HRef = "companylist.aspx?page=" & i + 1
        companyList.InnerHtml = strCom

    End Sub

    Protected Sub go_Click(ByVal sender As Object, ByVal e As EventArgs) Handles go.Click
        Response.Redirect("companyList.aspx?page=" & pageNum.Text)
    End Sub
End Class
